import java.util.LinkedList;
import java.util.Queue;

public class demo1 {
    class Solution {
        public int iceBreakingGame(int num, int target) {
            Queue<Integer> queue=new LinkedList<>();
            for (int i = 0; i <num ; i++) {
                queue.offer(i);
            }
            while (queue.size()>1){
                for (int i = 0; i <target-1; i++) {
                    queue.offer(queue.poll());
                }
                //除去目标
                queue.poll();
            }
            return queue.peek();
        }
    }
    class Solution2 {
        public int iceBreakingGame(int num, int target) {
            return dfs(num,target);
        }
        public int dfs(int num,int target){
            if(num==1){
                return 0;
            }
            //T通过删除的上一个元素获取
            return (dfs(num-1,target)+target)%num;
        }
    }
}
